﻿using Microsoft.Extensions.Options;
using System;
using System.Text;

namespace Microsoft.IdentityModel.Tokens
{
  public class JwtTokenValidationFactory
  {
    public JwtTokenValidation Options { get; private set; }

    public JwtTokenValidationFactory(IOptions<JwtTokenValidation> options)
    {
      Options = options.Value;
    }

    public TokenValidationParameters CreateTokenValidationParameters()
    {
      var result = new TokenValidationParameters
      {
        ValidateIssuer = false,
        ValidIssuer = Options.ValidIssuer,

        ValidateAudience = false,
        ValidAudience = Options.ValidAudience,

        ValidateIssuerSigningKey = true,
        IssuerSigningKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(Options.SecretKey)),

        RequireExpirationTime = true,
        ValidateLifetime = true,

        ClockSkew = TimeSpan.Zero
      };

      return result;
    }
  }
}